<script>
export default {
  props: ["modelValue"],
  emits: ["update:modelValue"],
  computed: {
    cake: {
      get() {
        return this.modelValue;
      },
      set(value) {
        this.$emit("update:modelValue", value);
      },
    },
  },
};
</script>

<template>
  <div class="cake-form">
    <div>
      <label for="name">商品名</label>
      <input type="text" id="name" v-model="cake.name" />
    </div>
    <div>
      <label for="pic">封面</label>
      <input type="text" id="pic" v-model="cake.pic" />
    </div>

    <div>
      <label for="price">定价</label>
      <input type="text" id="price" v-model="cake.price" />
    </div>
    
    <div class="intro">
      <label for="intro">简介</label>
      <textarea
        type="text"
        id="intro"
        rows="10"
        v-model="cake.intro"
      ></textarea>
    </div>
    <div>
      <button @click="$emit('cake-save')">提交</button>
    </div>
  </div>
</template>

<style scoped>
.cake-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
}

.cake-form > div {
  flex: 1 1 30%;
  margin: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.cake-form > div.intro {
  min-width: 100%;
}

.cake-form button {
  margin-left: 80px;
  width: 20%;
}

label {
  display: inline-block;
  width: 80px;
}

textarea,
input {
  flex: auto;
  box-sizing: border-box;
}
</style>
